#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

// 定义棋盘大小和操作次数
int n, m;
// 定义棋盘
vector<vector<int>> board;

// 向上移动并合并
pair<int, bool> moveUp() {
    int score = 0;
    bool changed = false;
    for (int j = 0; j < n; ++j) {
        vector<int> newCol;
        for (int i = 0; i < n; ++i) {
            if (board[i][j] != 0) {
                newCol.push_back(board[i][j]);
            }
        }
        vector<int> mergedCol;
        for (int i = 0; i < newCol.size(); ++i) {
            if (i + 1 < newCol.size() && newCol[i] == newCol[i + 1]) {
                mergedCol.push_back(newCol[i] * 2);
                score += newCol[i] * 2;
                changed = true;
                i++;
            } else {
                mergedCol.push_back(newCol[i]);
            }
        }
        for (int i = 0; i < n; ++i) {
            if (i < mergedCol.size()) {
                if (board[i][j] != mergedCol[i]) {
                    changed = true;
                }
                board[i][j] = mergedCol[i];
            } else {
                if (board[i][j] != 0) {
                    changed = true;
                }
                board[i][j] = 0;
            }
        }
    }
    return {score, changed};
}

// 向下移动并合并
pair<int, bool> moveDown() {
    int score = 0;
    bool changed = false;
    for (int j = 0; j < n; ++j) {
        vector<int> newCol;
        for (int i = n - 1; i >= 0; --i) {
            if (board[i][j] != 0) {
                newCol.push_back(board[i][j]);
            }
        }
        vector<int> mergedCol;
        for (int i = 0; i < newCol.size(); ++i) {
            if (i + 1 < newCol.size() && newCol[i] == newCol[i + 1]) {
                mergedCol.push_back(newCol[i] * 2);
                score += newCol[i] * 2;
                changed = true;
                i++;
            } else {
                mergedCol.push_back(newCol[i]);
            }
        }
        for (int i = n - 1; i >= 0; --i) {
            if (n - 1 - i < mergedCol.size()) {
                if (board[i][j] != mergedCol[n - 1 - i]) {
                    changed = true;
                }
                board[i][j] = mergedCol[n - 1 - i];
            } else {
                if (board[i][j] != 0) {
                    changed = true;
                }
                board[i][j] = 0;
            }
        }
    }
    return {score, changed};
}

// 向左移动并合并
pair<int, bool> moveLeft() {
    int score = 0;
    bool changed = false;
    for (int i = 0; i < n; ++i) {
        vector<int> newRow;
        for (int j = 0; j < n; ++j) {
            if (board[i][j] != 0) {
                newRow.push_back(board[i][j]);
            }
        }
        vector<int> mergedRow;
        for (int j = 0; j < newRow.size(); ++j) {
            if (j + 1 < newRow.size() && newRow[j] == newRow[j + 1]) {
                mergedRow.push_back(newRow[j] * 2);
                score += newRow[j] * 2;
                changed = true;
                j++;
            } else {
                mergedRow.push_back(newRow[j]);
            }
        }
        for (int j = 0; j < n; ++j) {
            if (j < mergedRow.size()) {
                if (board[i][j] != mergedRow[j]) {
                    changed = true;
                }
                board[i][j] = mergedRow[j];
            } else {
                if (board[i][j] != 0) {
                    changed = true;
                }
                board[i][j] = 0;
            }
        }
    }
    return {score, changed};
}

// 向右移动并合并
pair<int, bool> moveRight() {
    int score = 0;
    bool changed = false;
    for (int i = 0; i < n; ++i) {
        vector<int> newRow;
        for (int j = n - 1; j >= 0; --j) {
            if (board[i][j] != 0) {
                newRow.push_back(board[i][j]);
            }
        }
        vector<int> mergedRow;
        for (int j = 0; j < newRow.size(); ++j) {
            if (j + 1 < newRow.size() && newRow[j] == newRow[j + 1]) {
                mergedRow.push_back(newRow[j] * 2);
                score += newRow[j] * 2;
                changed = true;
                j++;
            } else {
                mergedRow.push_back(newRow[j]);
            }
        }
        for (int j = n - 1; j >= 0; --j) {
            if (n - 1 - j < mergedRow.size()) {
                if (board[i][j] != mergedRow[n - 1 - j]) {
                    changed = true;
                }
                board[i][j] = mergedRow[n - 1 - j];
            } else {
                if (board[i][j] != 0) {
                    changed = true;
                }
                board[i][j] = 0;
            }
        }
    }
    return {score, changed};
}

// 生成新数字
void generateNewNumber(int k, int v) {
    vector<pair<int, int>> emptyCells;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            if (board[i][j] == 0) {
                emptyCells.emplace_back(i, j);
            }
        }
    }
    int r = emptyCells.size();
    int index = (1 + k % r) - 1;
    board[emptyCells[index].first][emptyCells[index].second] = v;
}

int main() {
    cin >> n >> m;
    board.resize(n, vector<int>(n, 0));

    int x1, y1, v1, x2, y2, v2;
    cin >> x1 >> y1 >> v1 >> x2 >> y2 >> v2;
    board[x1 - 1][y1 - 1] = v1;
    board[x2 - 1][y2 - 1] = v2;

    int validMoves = 0;
    int totalScore = 0;

    for (int i = 0; i < m; ++i) {
        int d, k, v;
        cin >> d >> k >> v;
        pair<int, bool> result;
        if (d == 0) {
            result = moveUp();
        } else if (d == 1) {
            result = moveDown();
        } else if (d == 2) {
            result = moveLeft();
        } else if (d == 3) {
            result = moveRight();
        }
        if (result.second) {
            validMoves++;
            totalScore += result.first;
            generateNewNumber(k, v);
        } else {
            break;
        }
    }

    cout << validMoves << endl;
    cout << totalScore << endl;

    return 0;
}
